'''类的继承'''
class Father:
    monery =1000
    def __init__(self,name):
        self.name = name
        print('输出的爸爸是:%s' %self.name)
    def hitson1(self):
        print('%s正在打儿子' %self.name)
    def hitson(self,name):
        print("%s正在被他爸爸%s打 " %(name,self.name))
    @property
    # '''静态属性  实例直接不用传参数调用类的方法s1.teach'''
    def teach(self):
        return '%s正在教儿子写作业' % self.name
    @classmethod
    # '''类方法、不通过实例、类直接调用自己的方法'''
    def teachSwim(cls):
        print('%s正在教儿子学游泳' % cls)
    @staticmethod
    # '''类的静态方法、不依赖类和实例对象'''
    def teachwalk(a,b,c):
        print("%s,%s,%s三个都在教幼儿学习走路"%(a,b,c))

class Son(Father):
    pass
s1=Son("张三")
print(Father.__dict__)
print(Son.__dict__)
print(s1.monery)
print(s1.hitson1())
print(s1.hitson("萌萌"))
print(s1.teach)   # @property >>>张三正在教儿子写作业
print(Son.teachSwim()) # 函数不通过实例、自己调用函数的属性@classmothed
'''类、集成类、实例对象均可静态方法调用类的函数属性  @classmethod'''
print(Son.teachwalk("haifeng","alex","yuanhao"))
print(s1.teachwalk("haifeng","alex","yuanhao"))
print(Father.teachwalk("haifeng","alex","yuanhao"))

print("------子父类均有自己初始化对象函数---------")
class Dad:
    '''父类中有初始化'''
    monery = 1000
    def __init__(self, name):
        self.name = name
        print('输出的爸爸是:%s' % self.name)
    def hitson1(self):
        print('%s正在打儿子' % self.name)
class Daughter(Dad):
    '''方法重写：子类中也有初始化、与父类不一致时、走自己的方法'''
    def __init__(self, name, age):
        self.name = name
        self.age = age
    def hitson(self):
        print("来着子类自己的方法")
d1=Daughter("萌萌",16)
d1.hitson()
# ----归一化父类添加一个装饰器@abc.abstractmethod-------
import abc
class AllFileHandle(metaclass=abc.ABCMeta):
    '''对子类继承的时候进行限制必须有主类的方法
    器方法不用实现、也不用实例化、只是为了规范统一'''
    def __init__(self,filename):
        self.filename=filename
    @abc.abstractmethod
    def  read(self):
        pass
    @abc.abstractmethod
    def write(self):
        pass

class FileHald(AllFileHandle):
    def read(self):
        pass
    def write(self):
        pass
# --------------子类中调用父类----------------------
# class Traffic:
#     Country='China'
#     def __init__(self,name,speed,load,power):
#         self.name=name
#         self.speed=speed
#         self.load=load
#         self.power=power
#     def run(self):
#         print('%s开动了' % self.name)
#         print('%s开动了' % self.name)
#         print('%s开动了' % self.name)
#         print('%s开动了' % self.name)
# class Subway(Traffic):
#     def __init__(self,name,speed,load,power,linename,destination):
#         Traffic.__init__(self,name,speed,load,power)
#         self.linename=linename
#         self.destination =destination
#     def run(self):
#         Traffic.run(self)
#         # print("%s %s开动了"%(self.name,self.linename))
#     def showdetail(self):
#         print("%s %s %d %s %s %s" %(self.name,self.speed,\
#         self.load,self.power,self.linename,self.destination))
# s1=Subway('重庆地铁','196km/h',1000000,'电','10号线','江北机场')
# s1.run()
# s1.showdetail()
# ------super()类的继承与派生------------
class Traffic:
    Country='China'
    def __init__(self,name,speed,load,power):
        self.name = name
        self.speed = speed
        self.load = load
        self.power = power
    def run(self):
        print('%s开动了' % self.name,self.speed,self.load,self.power)
        print('%s开动了' % self.name,self.speed,self.load,self.power)
        print('%s开动了' % self.name,self.speed,self.load,self.power)
        print('%s开动了' % self.name,self.speed,self.load,self.power)
class Subway(Traffic):
    def __init__(self,name,speed,load,power,linename,destination):
        # Traffic.__init__(self,name,speed,load,power)
        super().__init__(name,speed,load,power)
        self.linename = linename
        self.destination = destination
    def run(self):
        # Traffic.run(self)
        super().run()
        # print("%s %s开动了"%(self.name,self.linename))
    def showdetail(self):
        print("%s %s %d %s %s %s" %(self.name,self.speed,\
        self.load,self.power,self.linename,self.destination))
t1=Traffic('重庆地铁','196km/h',1000000,'电')
print(t1.__dict__)
t1.run()

print("--------------")
s2 = Subway('重庆地铁','196km/h',1000000,'电','10号线','江北机场')
s2.run()
s2.showdetail()
